#include <iostream>

using namespace std;


typedef unsigned long long LL;
const int N = 1e6 + 10;

LL st[N];
int top;

int main()
{
	int T; cin >> T;
	while (T--)
	{
		top = 0; //清空栈
		int n; cin >> n;
		while (n--)
		{
			string op; cin >> op;
			if (op == "push")
			{
				LL x; cin >> x;
				st[++top] = x;
			}
			else if (op == "pop")
			{
				if (top == 0) cout << "Empty" << endl;
				else top--;
			}
			else if (op == "query")
			{
				if (top == 0) cout << "Anguei!" << endl;
				else cout << st[top] << endl;
			}
			else
			{
				cout << top << endl;
			}
		}
	}
}

